package com.zhuiyun.project.api.plan.fitnessType.service.impl;

import com.zhuiyun.project.api.plan.fitnessPurpose.service.FitnessPurposeService;
import com.zhuiyun.project.api.plan.fitnessPurpose.entity.FitnessPurpose;
import com.zhuiyun.project.api.plan.fitnessPurpose.mapper.FitnessPurposeMapper;
import com.zhuiyun.project.api.plan.fitnessType.entity.FitnessType;
import com.zhuiyun.project.api.plan.fitnessType.mapper.FitnessTypeMapper;
import com.zhuiyun.project.api.plan.fitnessType.service.FitnessTypeService;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import com.zhuiyun.project.utils.pageUtil.PageResult;
import com.zhuiyun.project.utils.validator.ValidatorUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName FitnessActionServiceImpl
 * @Description TODO
 * @Author ys
 * @Date 2023/11/2 9:01
 **/
@Service
public class FitnessTypeServiceImpl implements FitnessTypeService {
    @Resource
    private FitnessTypeMapper fitnessTypeMapper;
    /**
     * @Author 杨珅
     * @Description todo 健身类型查询
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public PageResult selectAll(PageRequest pageRequest, String fitnessTypeName,Integer fitnessPurposeId,String venueUniqueIdentifier) {
        MybatisPageHelper.startPage(pageRequest);// 使用MybatisPageHelper实现分页功能，设置分页信息
        List<FitnessType> TypeList = fitnessTypeMapper.selectAll(pageRequest, fitnessTypeName,fitnessPurposeId,venueUniqueIdentifier);// 调用ArticleReviewMapper的getArticle方法查询文章列表\
        return MybatisPageHelper.getPageResult(TypeList);
    }
    /**
     * @Author 杨珅
     * @Description todo 健身类型新增
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult insertFitnessType(FitnessType fitnessType)throws CommonException {
        if (ValidatorUtil.ValidationObject(fitnessType)){
            fitnessType.setCreateTime(new Date());
            fitnessType.setUpdateTime(new Date());
            int i = fitnessTypeMapper.insertFitnessType(fitnessType);
            if (i >= 1) {
                return CommonResult.ok(EmErrorCode.SAVE_OK);
            }else {
                return CommonResult.ok(EmErrorCode.SAVE_ERROR);
            }
        } else{
            return CommonResult.ok(EmErrorCode.SAVE_ERROR);
        }
    }
    /**
     * @Author 杨珅
     * @Description todo 健身类型新增
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult updateFitnessType(FitnessType fitnessType)throws CommonException {
        if (ValidatorUtil.ValidationObject(fitnessType)){
            fitnessType.setCreateTime(new Date());
            fitnessType.setUpdateTime(new Date());
            int i = fitnessTypeMapper.updateFitnessType(fitnessType);
            if (i >= 1) {
                return CommonResult.ok(EmErrorCode.UPDATE_OK);
            }else {
                return CommonResult.ok(EmErrorCode.UPDATE_ERROR);
            }
        } else{
            return CommonResult.ok(EmErrorCode.UPDATE_ERROR);
        }
    }
    /**
     * @Author 杨珅
     * @Description todo 健身类型删除
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult deleteFitnessType(FitnessType fitnessType) {
        return CommonResult.ok(fitnessTypeMapper.deleteFitnessType(fitnessType));
    }
}
